package de.fuberlin.inf.alp3.ue06;

public class Equal extends BinaryOp {

    Equal(Expression left, Expression right) {
        super(left, right);
    }

    @Override
    public Expression eval() {
        try {
            return new Boolean( (((Boolean) left.eval()).getValue()) == (((Boolean) right.eval()).getValue()));
        } catch (ClassCastException exc) {
            // one of the two expressions wasn't a boolean
            try {
                return new Boolean( (((Integer) left.eval()).getValue()) == (((Integer) right.eval()).getValue()));
            } catch (ClassCastException e) {
                // one of the two expressions wasn't an integer
                return new Boolean(false);
            }
        }
    }
}